package ign.behaviours.building;

import ign.Performatives;
import ign.agents.Building;
import jade.core.AID;
import jade.core.behaviours.Behaviour;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;

/**
 * Classe s'occupant de trier la boîte aux lettres.
 * @author Simon Bourigaut & Ghislain Di Paolo
 */
public class BuildingListening extends Behaviour {
	private static final long serialVersionUID = 2646593558008167355L;
	Building me = (Building) myAgent;

	@Override
	public void action() {
		MessageTemplate pattern = MessageTemplate.MatchPerformative(Performatives.IN_CONFLICT);
		
		for(ACLMessage msg = myAgent.receive(pattern); msg != null; msg = myAgent.receive(pattern) ) {
		
			int perf = msg.getPerformative();
			
			if (perf == Performatives.IN_CONFLICT) {	
				AID aid = new AID(msg.getContent(), AID.ISGUID);
				
				myAgent.addBehaviour(new Move(aid)) ;	
			}
		}
	}

	@Override
	public boolean done() {
		
		return false; 
	}

}
